/**
 * @file AHT10Sensor.cpp
 * @brief AHT10温湿度传感器驱动类实现
 */

#include "AHT10Sensor.h"

AHT10Sensor::AHT10Sensor() {
    sensorFound = false;
}

bool AHT10Sensor::init() {
    Serial.println("Initializing AHT10 sensor...");
    
    if (aht.begin()) {
        sensorFound = true;
        Serial.println("AHT10 sensor initialized successfully");
        return true;
    } else {
        Serial.println("AHT10 sensor not found, please check connection");
        sensorFound = false;
        return false;
    }
}

bool AHT10Sensor::readData() {
    if (!sensorFound) {
        return false;
    }
    
    // 使用库函数读取传感器数据
    if (aht.getEvent(&humidity, &temp)) {
        return true;
    } else {
        Serial.println("Failed to read AHT10 sensor data");
        return false;
    }
}

float AHT10Sensor::getTemperature() {
    return temp.temperature;
}

float AHT10Sensor::getHumidity() {
    return humidity.relative_humidity;
}

bool AHT10Sensor::isSensorFound() {
    return sensorFound;
}